package com.ruoyi.project.surveys.controller;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.surveys.domain.SurveysInfo;
import com.ruoyi.project.surveys.service.ISurveysInfoService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 问卷基础信息Controller
 * 
 * @author zhimin-hu
 * @date 2020-05-02
 */
@RestController
@RequestMapping("/surveys/info")
public class SurveysInfoController extends BaseController
{
    @Autowired
    private ISurveysInfoService surveysInfoService;

    /**
     * 查询问卷基础信息列表
     */
    @PreAuthorize("@ss.hasPermi('surveys:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(SurveysInfo surveysInfo)
    {
        startPage();
        List<SurveysInfo> list = surveysInfoService.selectSurveysInfoList(surveysInfo);
        return getDataTable(list);
    }

    /**
     * 导出问卷基础信息列表
     */
    @PreAuthorize("@ss.hasPermi('surveys:info:export')")
    @Log(title = "问卷基础信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SurveysInfo surveysInfo)
    {
        List<SurveysInfo> list = surveysInfoService.selectSurveysInfoList(surveysInfo);
        ExcelUtil<SurveysInfo> util = new ExcelUtil<SurveysInfo>(SurveysInfo.class);
        return util.exportExcel(list, "info");
    }

    /**
     * 获取问卷基础信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('surveys:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(surveysInfoService.selectSurveysInfoById(id));
    }

    /**
     * 新增问卷基础信息
     */
    @PreAuthorize("@ss.hasPermi('surveys:info:add')")
    @Log(title = "问卷基础信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SurveysInfo surveysInfo)
    {
        surveysInfo.setCreateBy(SecurityUtils.getUsername());
        return toAjax(surveysInfoService.insertSurveysInfo(surveysInfo));
    }

    /**
     * 修改问卷基础信息
     */
    @PreAuthorize("@ss.hasPermi('surveys:info:edit')")
    @Log(title = "问卷基础信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SurveysInfo surveysInfo)
    {
        surveysInfo.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(surveysInfoService.updateSurveysInfo(surveysInfo));
    }

    /**
     * 删除问卷基础信息
     */
    @PreAuthorize("@ss.hasPermi('surveys:info:remove')")
    @Log(title = "问卷基础信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(surveysInfoService.deleteSurveysInfoByIds(ids));
    }
}
